<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var minunmPickup = function (cards) {
      const map = new Map()
      let ans = Infinity
      for (let i = 0; i < cards.length; i++) {
        if (map.has(cards[i])) {
          const cur = i - (map.get(cards[i])) + 1
          ans = Math.min(ans, cur)
        }
        map.set(cards[i], i)
      }
      return ans === Infinity ? -1 : ans
    }
    console.log(minunmPickup(cards = [3, 4, 2, 3, 4, 7]))
  </script>
</body>

</html>